package com.voicechat.firstmet.activity;

import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.voicechat.firstmet.R;
import com.voicechat.firstmet.base.BaseActivity;
import com.voicechat.firstmet.fragment.BlindDatePlaceOrderFragment;
import com.voicechat.firstmet.fragment.MyReceiveShareGirlsOrderFragment;
import com.voicechat.firstmet.utils.StatusBarUtils;
import com.voicechat.firstmet.view.NoScrollViewPager;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ProjectName: FirstMet
 * @Package: com.voicechat.firstmet.activity
 * @ClassName: OrderAndShareGirlsActivity
 * @Description: 隐约订单和共享闺蜜页面
 * @Author: ljp
 * @CreateDate: 2019/1/19 11:20
 * @Version: 1.0
 */
public class OrderAndShareGirlsActivity extends BaseActivity {
    @BindView(R.id.linear_back)
    LinearLayout linearBack;
    @BindView(R.id.tv_order)
    TextView tvOrder;
    @BindView(R.id.tv_my_Girls)
    TextView tvMyGirls;
    @BindView(R.id.view_page)
    NoScrollViewPager viewPage;
    private MyAdapter mAdapter;
    private ArrayList<Fragment> fragments;
    private String TAG = "OrderAndShareGirlsActivity";
    private Handler handler;

    @Override
    protected int setStatusBarColor() {
        return 0;
    }

    @Override
    protected boolean isSettingStatusBarText() {
        return false;
    }

    @Override
    protected int loadLayout() {
        return R.layout.activity_order_girls;
    }

    @Override
    protected void initLayout(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        //透明状态栏
        StatusBarUtils.Full(this);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        initView();
    }
    /**
     * @return
     * @method
     * @description 数据控件实例化
     * @date: 2019/1/4 20:00
     * @author: ljp
     */
    private void initView() {
        initViewPager();
    }
    private void initViewPager() {
        fragments = new ArrayList<>();
        fragments.add(BlindDatePlaceOrderFragment.newInstance());
        fragments.add(MyReceiveShareGirlsOrderFragment.newInstance());
        mAdapter = new MyAdapter(getSupportFragmentManager());
        viewPage.setAdapter(mAdapter);
        viewPage.addOnAdapterChangeListener(new ViewPager.OnAdapterChangeListener() {
            @Override
            public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter pagerAdapter, @Nullable PagerAdapter pagerAdapter1) {
            }
        });
        viewPage.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {
            }
            @Override
            public void onPageSelected(int i) {
                if (i == 0) {
                    clearSelection();
                    tvOrder.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    tvOrder.setTextColor(getResources().getColor(R.color.color2D2D2D));
                } else {
                    clearSelection();
                    tvMyGirls.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                    tvMyGirls.setTextColor(getResources().getColor(R.color.color2D2D2D));
                }
            }
            @Override
            public void onPageScrollStateChanged(int i) {
            }
        });
    }
    @Override
    protected void clearSelection() {//清空底部Tab的选中状态,当点击的时候再自定义选中Tab的状态
        super.clearSelection();
        tvMyGirls.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        tvOrder.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        tvOrder.setTextColor(getResources().getColor(R.color.colorAAAAAA));
        tvMyGirls.setTextColor(getResources().getColor(R.color.colorAAAAAA));
    }
    @OnClick({R.id.linear_back, R.id.tv_order, R.id.tv_my_Girls})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.linear_back:
                finish();
                break;
            case R.id.tv_order:
                viewPage.setCurrentItem(0);
                clearSelection();
                tvOrder.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tvOrder.setTextColor(getResources().getColor(R.color.color2D2D2D));
                break;
            case R.id.tv_my_Girls:
                viewPage.setCurrentItem(1);
                clearSelection();
                tvMyGirls.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
                tvMyGirls.setTextColor(getResources().getColor(R.color.color2D2D2D));
                break;
        }
    }

    private class MyAdapter extends FragmentStatePagerAdapter {

        public MyAdapter(FragmentManager fm) {
            super(fm);
            // TODO Auto-generated constructor stub
        }

        @Override
        public Fragment getItem(int arg0) {
            // TODO Auto-generated method stub
            return fragments.get(arg0);
        }
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return fragments.size();
        }
    }
}
